## -*- coding: utf-8 -*-
#import web
#import pyamf
#from pyamf import remoting
#from pyamf.remoting import gateway
#
#class WebpyGateway(gateway.BaseGateway):
#    def __init__(self, services, **kwargs):
#        gateway.BaseGateway.__init__(self, services, **kwargs)
#        
#    def getResponse(self, request, environ):
#        response = remoting.Envelope(request.amfVersion, request.clientType)
#        for name, message in request:
#            processor = self.getProcessor(message)
#            environ['pyamf.request'] = message
#            response[name] = processor(message, http_request=environ)
#        
#        return response
#    
#    def POST(self):
#        print "try login"
#        
#    def __call__(self):
#        if "POST" != web.ctx.method:
#            raise web.badrequest()
#        
#        environ = web.ctx.environ
#        body = environ['wsgi.input'].read(int(environ['CONTENT_LENGTH']))
#        stream = None
#        timezone_offset = self._get_timezone_offset()
#        
#        try:
#            request = remoting.decode(body, strict=self.strict,
#                                      logger=self.logger, timezone_offset=timezone_offset)
#        except (pyamf.DecodeError, IOError):
#            if self.logger:
#                self.logger.exception(gateway.format_exception())
#            raise web.badrequest()
#        except (KeyboardInterrupt, SystemExit):
#            raise
#        except:
#            if self.logger:
#                self.logger.exception(gateway.format_exception())
#            raise web.internalerror("Can't decode AMF request.")
#        
#        if self.logger:
#            self.logger.info("AMF Request: %r" % request)
#        
#        try:
#            response = self.getResponse(request, environ)
#        except (KeyboardInterrupt, SystemExit):
#            raise
#        except:
#            if self.logger:
#                self.logger.exception(gateway.format_exception())
#            raise web.internalerror("Can't get response.")
#        
#        if self.logger:
#            self.logger.info("AMF Response: %r" % response)
#        
#        try:
#            stream = remoting.encode(response, strict=self.strict,
#                                     timezone_offset=timezone_offset)
#        except:
#            if self.logger:
#                self.logger.exception(gateway.format_exception())
#            raise web.internalerror("Can't encode AMF response.")
#        
#        retvalue = stream.getvalue()
#        web.header("Content-Type", remoting.CONTENT_TYPE)
#        web.header("Content-Length", str(len(retvalue)))
#        web.header("Server", gateway.SERVER_NAME)
#        return retvalue